/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifSalidasAlmacen.java
 *
 * Created on 26-jul-2010, 9:22:12
 */

package GestionMovimientos;

import administracion.BeanBinding.TblBeanBindingDetalleSalida;
import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_Fecha;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.helper.VerificarDatos;
import administracion.propiedades.Propiedades;
import com.jidesoft.hints.ListDataIntelliHints;
import suministros.ejb30.TO.DetalleSalidaTO;
import suministros.ejb30.TO.LocalidadTO;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.AlmacenTO;
import suministros.ejb30.TO.CentroCostoTO;
import suministros.ejb30.TO.DetalleTransferenciaTO;
import suministros.ejb30.TO.ProyectoTO;
import suministros.ejb30.TO.SubAlmacenTO;
import suministros.ejb30.TO.TipoTO;
import suministros.ejb30.TO.TransferenciaTO;
import suministros.ejb30.TO.ZonaTO;
import suministros.ejb30.entity.CentroCosto;
import suministros.ejb30.entity.DetalleMovimiento;
import suministros.ejb30.entity.DetalleMovimientoPK;
import suministros.ejb30.entity.Movimiento;
import suministros.ejb30.entity.Parametros;
import suministros.ejb30.entity.Proyecto;
import suministros.ejb30.entity.Suministros;
import suministros.ejb30.entity.Tipo;
import suministros.ejb30.entity.Transferencia;
import suministros.ejb30.helper.Utiles_Convertir;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import suministros.ejb30.TO.EmpresaTO;
import suministros.ejb30.entity.Localidad;

/**
 *
 * @author Diana
 */
public class jifSalidasAlmacen extends javax.swing.JInternalFrame {
     JFrame padre;
     private MaskFormatter mascaraFechaIngreso;
     List<EmpresaTO> empresas;
     List<ZonaTO> zonas;
     List<AlmacenTO> almacenes;
     List<SubAlmacenTO> subalmacenes;
     List<LocalidadTO> listaLocalidad;
     TransferenciaTO transferencia;
     List<DetalleSalidaTO> detallesSalida;   
     List<TblBeanBindingDetalleSalida> detallesbindingsalida;
     private JTableBinding jTableBinding;
     List<DetalleTransferenciaTO> detallestransferencia;
     private ListDataIntelliHints intelliHintsCodigos;
     List listacodigo= new ArrayList();
     List listaTipos = null;
     String codSalida= null;
     List<TipoTO> listaTiposMoneda=new ArrayList();

     int[] porcentajes= {14,45,13,14,14};
    /** Creates new form jifSalidasAlmacen */
    public jifSalidasAlmacen(JFrame padre) {
        if(Listas.getInventario()){
            Utiles_MensajesDialogo.mensajeAlerta("Hay un inventario iniciado \nNo se pueden realizar salidas de almacen");
            this.dispose();
       }
        else{

            this.padre=padre;
            construirMascaras();
            initComponents();
            empresas = Listas.getEmpresas();
            if(empresas.isEmpty()){
                this.jCheckBox1.setEnabled(false);
            }
            this.jCheckBox1.setSelected(false);
            this.llenarComboEmpresa();
            this.llenarComboZonas();
            this.llenarComboTipoMovimiento();
            this.llenarComboTipoSalida();
            this.llenarComboAlmacen();
            this.llenarComboSubAlmacen();
            llenarComboTipoMoneda();
            llenarComboTipoDocumento();
            this.jbtAceptar.setEnabled(false);
            detallesSalida= new  ArrayList<DetalleSalidaTO>();
            detallestransferencia = new ArrayList<DetalleTransferenciaTO>();
            detallesbindingsalida= new ArrayList<TblBeanBindingDetalleSalida>();
            this.jcbEmpresa.setEnabled(false);
            this.cargaHintsIndependientes();
            this.jlblSerie.setVisible(false);
            this.jlblNumero.setVisible(false);
            this.jtfSerie.setVisible(false);
            this.jtfNumero.setVisible(false);
        }

    }
 private void construirMascaras() {
    try {
      this.mascaraFechaIngreso = new MaskFormatter("##/##/####");
    } catch (ParseException ex) {
      Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
      ex.printStackTrace();
    }
  }
   private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
         if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

   
  private void llenarComboTipoSalida() {
        List listaTipos2 = null;
        List listaTipos_cbo2 = this.cboBeanBindingTipo2.getLista();
        listaTipos_cbo2.clear();
        try
        {
          listaTipos2 = Listas.getTipo_porTabla("Tipo_Salida");

          this.cboBeanBindingTipo2.setLista(listaTipos2);
          this.bindingGroup.bind();
          this.jcbTipoIngreso.updateUI();
          this.jcbTipoIngreso.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Ingresos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
   private void llenarComboTipoDocumento() {
        List listaTipos3 = null;
        List listaTipos_cbo3 = this.cboBeanBindingTipo3.getLista();
        listaTipos_cbo3.clear();
        try
        {
          listaTipos3 = Listas.getTipo_porTabla("tipo_documento");

          this.cboBeanBindingTipo3.setLista(listaTipos3);
          this.bindingGroup.bind();

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos documentos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    private void llenarComboTipoMoneda() {
        listaTiposMoneda = null;
        List listaTipos_cbo1 = this.cboBeanBindingTipo4.getLista();
        listaTipos_cbo1.clear();
        try
        {
          listaTiposMoneda = Listas.getTipo_porTabla("Tipo_moneda");

          this.cboBeanBindingTipo4.setLista(listaTiposMoneda);
          this.bindingGroup.bind();
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Tipos Monedas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
 private void llenarComboZonas() {
        zonas = null;
        List listaPaises_cbo = this.cboBeanBindingZona1.getLista();
        listaPaises_cbo.clear();
        try
        {
          zonas = Listas.getZonas();
          this.cboBeanBindingZona1.setLista(zonas);
          this.bindingGroup.bind();
          this.jcbZona.updateUI();
          this.jcbZona.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener zonas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      private void llenarComboLocalidad()
      {
        try {
            listaLocalidad = null;
            ZonaTO selected = (ZonaTO)this.jcbZona.getSelectedItem();
            List listaLocal_cbo = this.cboBeanBindingLocalidad1.getLista();
            listaLocal_cbo.clear();
            listaLocalidad = Listas.getLocalidadZona(selected);
            this.cboBeanBindingLocalidad1.setLista(listaLocalidad);
            this.bindingGroup.bind();
        }
        catch (Exception e) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener localidades\n" + e.getMessage());
          e.printStackTrace();
          Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, e);
        }
      }

     public ZonaTO obtenerZona(String nombre){
        ZonaTO dep= new ZonaTO();
        for(int i=0 ; i<this.zonas.size(); i++){
            if((((ZonaTO)zonas.get(i)).getNom_zona().trim()).compareTo(nombre)==0){
                dep= (ZonaTO)zonas.get(i);
            }
        }
        return dep;
    }
     public AlmacenTO obtenerAlmacen(String nombre){
        AlmacenTO dep= new AlmacenTO();
        for(int i=0 ; i<this.almacenes.size(); i++){
            if(((AlmacenTO)almacenes.get(i)).getDescripcion().trim().compareTo(nombre)==0){
                dep= (AlmacenTO)almacenes.get(i);
            }
        }
        return dep;
    }
  public SubAlmacenTO obtenerSubAlmacen(String nombre){
        SubAlmacenTO dep= new SubAlmacenTO();
        for(int i=0 ; i<this.subalmacenes.size(); i++){
            if(((SubAlmacenTO)subalmacenes.get(i)).getDescripcion().compareTo(nombre)==0){
                dep= (SubAlmacenTO)subalmacenes.get(i);
            }
        }
        return dep;
    }
      public LocalidadTO obtenerLocalidad(String nombre){
        LocalidadTO dep= new LocalidadTO();
        for(int i=0 ; i<this.listaLocalidad.size(); i++){
             if((((LocalidadTO)listaLocalidad.get(i)).getNom_localidad().trim()).compareTo(nombre)==0){
                dep= (LocalidadTO)listaLocalidad.get(i);
            }
        }
        return dep;

    }
      public EmpresaTO obtenerEmpresa(String codigo){
        EmpresaTO dep= new EmpresaTO();
        for(int i=0 ; i<this.empresas.size(); i++){
            if((((EmpresaTO)empresas.get(i)).getCodigo().trim()).compareTo(codigo)==0){
                dep= (EmpresaTO)empresas.get(i);
            }
        }
        return dep;
    }
  
      public List<DetalleSalidaTO> convertirDetalles_SalidaTr( List<DetalleTransferenciaTO> listadetalles){
           List<DetalleSalidaTO> deSalida= new ArrayList<DetalleSalidaTO>();
          for(DetalleTransferenciaTO deta: listadetalles){
                 DetalleSalidaTO ing= new DetalleSalidaTO( deta.getSuministro(), deta.getDescsuministro(), deta.getUnidad(),deta.getCantidad(), new BigDecimal(0));
                 deSalida.add(ing);
             }
          return deSalida;
      }

    private void llenarComboTipoMovimiento() {

        List listaTipos_cbo = this.cboBeanBindingTipo1.getLista();
        listaTipos_cbo.clear();
        try
        {
         listaTipos = Listas.getTipo_porTabla("tipo_Movimiento");

        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener tipos documentos\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    public static java.sql.Timestamp verificaFecha(String fecha)throws Exception{
        java.sql.Timestamp fecharegreso=null;
        fecharegreso=java.sql.Timestamp.valueOf(fecha);
        return fecharegreso;
    }
    private void llenarComboAlmacenZona() {
           try {
                  if (this.jcbZona.getSelectedItem() != null) {
                    ZonaTO selected = (ZonaTO)this.jcbZona.getSelectedItem();
                    List listaAlmacen = null;
                    List listaAlmacen_cbo = this.cboBeanBindingAlmacen1.getLista();
                    listaAlmacen_cbo.clear();
                    listaAlmacen = Listas.getAlmacenEnZona(selected);
                    this.cboBeanBindingAlmacen1.setLista(listaAlmacen);
                    this.bindingGroup.bind();
                    this.jcbAlmacen.updateUI();
                    this.jcbAlmacen.setSelectedIndex(-1);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }
     private void llenarComboUbicacionAlmacen() {
       try {
                  if (this.jcbAlmacen.getSelectedItem() != null) {
                    AlmacenTO selected = (AlmacenTO)this.jcbAlmacen.getSelectedItem();
                    List listaSubAlmacen = null;
                    List listaSubAlmacen_cbo = this.cboBeanBindingSubAlmacen1.getLista();
                    listaSubAlmacen_cbo.clear();
                    listaSubAlmacen = Listas.getSubAlmacenEnAlmacen(selected);
                    this.cboBeanBindingSubAlmacen1.setLista(listaSubAlmacen);
                    this.bindingGroup.bind();
                    this.jcbUbicacion.updateUI();
                    this.jcbUbicacion.setSelectedIndex(-1);
                  }
          }
            catch (Exception e) {
              Utiles_MensajesDialogo.mensajeAlerta("Error al obtener Sub Almacenes\n" + e.getMessage());
              e.printStackTrace();
              Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, e);
            }
     }
      public void limpiar(){
        this.detallesSalida.clear();
        this.jtfFecha.setText("");
        this.jcbAlmacen.setSelectedIndex(-1);
        this.jcbUbicacion.setSelectedIndex(-1);
        this.jcbEmpresa.setEnabled(true);
        this.jcbZona.setEnabled(true);
        this.jbtAceptar.setEnabled(false);

    }
 public void GenerarReporte(String codigo){
     if(codigo!=null){
        JasperViewer jv = null;
        JasperPrint jp = null;
        Map parametros = new HashMap();
        parametros.put("idMovimiento", codigo);
        try {
            jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("NotaSalidaFLP.jasper", parametros);
            jv = new JasperViewer(jp, false);
            jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        }catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
     }
        
  }
 public void GenerarReporteTrans(String codigo){
     if(codigo!=null){
        JasperViewer jv = null;
        JasperPrint jp = null;
        Map parametros = new HashMap();
        parametros.put("idMovimiento", codigo);
        try {
            jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("NotaSalidaFLP.jasper", parametros);
            jv = new JasperViewer(jp, false);
            jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        }catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
     }
        
  }

 //PARA LA TRANSFERENCIA
 public void obtenerTransferencia(){
         try
        {
          transferencia= new TransferenciaTO();
          transferencia = GestionPedidosDelegate.getInstance().getDatosTransferencia(this.jtfOrden.getText().trim(), 1);
          if(transferencia.getEmpresa()!=null){
              boolean estado=false;
               String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
               if(emp.compareTo(transferencia.getEmpresa())==0){
                    estado=true;
              }         
              if(estado){
                  estado=false;
                  for(int i=0; i<zonas.size(); i++){
                      if(zonas.get(i).getNom_zona().compareTo(transferencia.getZona())==0){
                          estado=true;
                      }
                  }
                  if(estado){
                      this.jcbZona.setSelectedItem(this.obtenerZona(transferencia.getZona()));
                      this.jcbAlmacen.setSelectedItem(this.obtenerAlmacen(transferencia.getAlmacen()));
                      this.jcbUbicacion.setSelectedItem(this.obtenerSubAlmacen(transferencia.getSubalmacen()));
                      this.jcbZona.setEnabled(false);
                      if(this.jcbZona.getSelectedIndex()>=0){
                          llenarComboLocalidad();

                      }
                      obtenerDetallesTransferencia();
                      this.jbtAceptar.setEnabled(true);
                      this.jtfFecha.requestFocus();
                  }
                  else{
                         Utiles_MensajesDialogo.mensajeAlerta("La nota de transferencia no pertenece \n a las zonas asignadas al usuario");
                         this.limpiarTrans();
                  }

              }
              else{
                   Utiles_MensajesDialogo.mensajeAlerta("La nota de transferencia no pertenece \n a la empresa seleccionada");
                   this.limpiarTrans();
              }
              
          }
          else{
               
          }
        } catch (Exception ex) {
           Utiles_MensajesDialogo.mensajeAlerta("No se ha encontrado la transferencia o ya esta regitrada la salida");
           this.limpiarTrans();
           Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

  private void llenarComboAlmacen() {
        almacenes = null;
        List listaPaises_cbo = this.cboBeanBindingAlmacen1.getLista();
        listaPaises_cbo.clear();
        try
        {
          almacenes = Listas.getAlmacenes();
          this.cboBeanBindingAlmacen1.setLista(almacenes);
          this.bindingGroup.bind();
          this.jcbAlmacen.updateUI();
          this.jcbAlmacen.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener almacenes\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       private void llenarComboSubAlmacen() {
        subalmacenes = null;
        List listaPaises_cbo = this.cboBeanBindingSubAlmacen1.getLista();
        listaPaises_cbo.clear();
        try
        {
          subalmacenes = Listas.getSubalmacenes();
          this.cboBeanBindingSubAlmacen1.setLista(subalmacenes);
          this.bindingGroup.bind();
          this.jcbUbicacion.updateUI();
          this.jcbUbicacion.setSelectedIndex(-1);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener subalmacenes\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
       private void obtenerDetallesTransferencia() {
        try {

         this.detallestransferencia = GestionPedidosDelegate.getInstance().getDatosDetalleTransferencia(this.jtfOrden.getText());
         this.detallesSalida= this.convertirDetalles_SalidaTr(detallestransferencia);
        } catch (Exception ex) {
            Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
      if(detallestransferencia.isEmpty()){
           Utiles_MensajesDialogo.mensajeAlerta("No se han encontrado detalles pendientes de entregar");
      }

    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallestransferencia, this.jtDetalleSuministro);


    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descsuministro}"));

    columnBinding1.setColumnName("Denominacion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);


     JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding4.setColumnName("Cant.Entregar");
    columnBinding4.setColumnClass(BigDecimal.class);
    columnBinding4.setEditable(false);

    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();

     try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }

  }
   private void actualizarDetallesTransferencia() {

    this.bindingGroup = new BindingGroup();
    this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallestransferencia, this.jtDetalleSuministro);


    JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${suministro}"));

    columnBinding0.setColumnName("Codigo");
    columnBinding0.setColumnClass(String.class);
    columnBinding0.setEditable(false);

    JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${descsuministro}"));

    columnBinding1.setColumnName("Denominacion");
    columnBinding1.setColumnClass(String.class);
    columnBinding1.setEditable(false);

    JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

    columnBinding2.setColumnName("Unidad");
    columnBinding2.setColumnClass(String.class);
    columnBinding2.setEditable(false);

    JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding3.setColumnName("Cantidad");
    columnBinding3.setColumnClass(String.class);
    columnBinding3.setEditable(false);


     JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

    columnBinding4.setColumnName("Cant.Entregar");
    columnBinding4.setColumnClass(BigDecimal.class);
    columnBinding4.setEditable(false);

    this.bindingGroup.addBinding(this.jTableBinding);
    this.bindingGroup.bind();

     try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
        } catch (Exception ex) {
            Logger.getLogger(jifAdministrarStock.class.getName()).log(Level.SEVERE, null, ex);
        }

  }
        /*public String registrarSalidaTransferencia() throws Exception{
        String codigo=null;
        boolean estado=true;
        listaubicaciones= new ArrayList<UbicacionTO>();
        listaubicacionesNon= new ArrayList<UbicacionTO>();
        List<UbicacionTO> ubicacionesSumi= new ArrayList<UbicacionTO>(1);
        List<UbicacionTO> suministroUbi= new ArrayList<UbicacionTO>(1);
        List<DetalleTransferenciaTO> detallesTrans= new ArrayList<DetalleTransferenciaTO>(1);
        Movimiento mov= new Movimiento();

        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);
        Parametros param2 = Listas.getParametrosID("SU1");
        String ano = param2.getParam1();
        String mes = param2.getParam2();
        if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
        Utiles_MensajesDialogo.mensajeError("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
        }
        else{
        mov.setNumero(this.jtfNumero.getText());
        mov.setSerie(this.jtfSerie.getText());
        mov.setFecha(fecha);
        mov.setObservacion(this.jtaObservacion.getText());
        mov.setIdTransferencia(new Transferencia(transferencia.getCodigo()));
        mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(1)));
        mov.setIdAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()));
        mov.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
        mov.setIdSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbUbicacion.getSelectedItem()));
        mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem()));
        mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()));
        int indices[]=new int[this.detallesSalida.size()];
        Float cantiUl[]=new Float[this.detallesSalida.size()];
        Float cantiUt[]=new Float[this.detallesSalida.size()];
        Parametros param = Listas.getParametrosID("SU2");
        String tipo = param.getParam1();
        String subalmacen= ((SubAlmacenTO)this.jcbUbicacion.getSelectedItem()).getCodSubAlmacen();
        for(int i=0; i< detallesSalida.size(); i++){

             boolean encontrado=true;
             boolean nostock=false;
             int contador=0;
             Float cant=0.0f;
             Float monto=0.0f;
             String suministro=this.detallesSalida.get(i).getCodigo();
             Float cantidad= Float.parseFloat(this.jtDetalleSuministro.getValueAt(i, 4)+"");
             if(tipo.compareTo("PEPS")==0){
               listaubicaciones= GestionPedidosDelegate.getInstance().getListaUbicacionesAsc(suministro, subalmacen, mov.getEmpresa().getIdEmpresa());
               listaubicacionesNon=GestionPedidosDelegate.getInstance().getListaUbicacionesAscNon(suministro, subalmacen, mov.getEmpresa().getIdEmpresa());
             }
             if(tipo.compareTo("UEPS")==0){
               listaubicaciones= GestionPedidosDelegate.getInstance().getListaUbicacionesDesc(suministro, subalmacen, mov.getEmpresa().getIdEmpresa());
               listaubicacionesNon=GestionPedidosDelegate.getInstance().getListaUbicacionesDescNon(suministro, subalmacen, mov.getEmpresa().getIdEmpresa());
             }
             if(listaubicaciones.isEmpty()){
                  Utiles_MensajesDialogo.mensajeFracaso("No has suficiente cantidades del suministro: "+detallesSalida.get(i).getDenominacion());
                  estado=false;
             }

             else{
                     while(encontrado && contador<listaubicaciones.size()){
                     cant=cant+Float.parseFloat(listaubicaciones.get(contador).getCantidad()+"");
                         if(cant>=cantidad){
                            encontrado=false;
                            nostock=true;
                         }
                         else{
                            contador++;
                         }
                     }

                    if(nostock){
                     indices[i]=contador;
                     cantiUl[i]=cant-cantidad;// lo que queda en la casilla
                     cantiUt[i]=(Float.parseFloat(listaubicaciones.get(contador).getCantidad()+""))-(cantiUl[i]);//lo que se le da al pedido
                     for(int k=0; k<contador; k++){
                        monto=monto+Float.parseFloat(listaubicaciones.get(k).getMonto()+"");
                        suministroUbi.add(listaubicacionesNon.get(k));//para mostrar ubicaciones
                        UbicacionTO ubi= listaubicaciones.get(k);
                        ubi.setCantidad(new BigDecimal(0));
                        ubi.setMonto(new BigDecimal(0));
                        ubicacionesSumi.add(ubi);
                     }
                     //ubicaiones mostrar
                     UbicacionTO ubinon=listaubicacionesNon.get(contador);
                     ubinon.setCantidad(new BigDecimal(cantiUt[i]).setScale(2));
                     suministroUbi.add(ubinon);
                     //para modificar cantidades de ubicacion
                     UbicacionTO ubi=listaubicaciones.get(contador);
                     ubi.setCantidad(new BigDecimal(cantiUl[i]));
                     ubi.setMonto(new BigDecimal(cantiUl[i]*Float.parseFloat(listaubicaciones.get(contador).getPrecio()+"")));//monto que queda en la ubicacion
                     ubicacionesSumi.add(ubi);

                     monto=monto+(Float.parseFloat(listaubicaciones.get(contador).getPrecio()+"")*(cantiUt[i]));
                     this.detallestransferencia.get(i).setLocalidad(this.listaLocalidad.get(0).getId_localidad());
                     this.detallestransferencia.get(i).setZona(((ZonaTO)this.jcbZona.getSelectedItem()).getId_zona());
                     this.detallestransferencia.get(i).setFecha(fecha);
                     detallesTrans.add(detallestransferencia.get(i));
                  }
                   else{
                          Utiles_MensajesDialogo.mensajeFracaso("No has suficiente cantidades del suministro: "+detallesSalida.get(i).getDenominacion());
                          estado=false;
                     }
             }

        }
       codigo=null;
        if(estado){
            try {
              codigo= GestionPedidosDelegate.getInstance().insertarSalidaTran(Propiedades.getUsuario(),Propiedades.getMac(),mov, ubicacionesSumi, detallesTrans);
              Utiles_MensajesDialogo.mensajeExito();
              this.GenerarReporteTrans(codigo);
              jdMostrarUbicaciones jdAgregaDetalle=new jdMostrarUbicaciones(this,padre,true,suministroUbi );
              jdAgregaDetalle.setLocationRelativeTo(null);
              jdAgregaDetalle.setPadreDetalle(this);
              jdAgregaDetalle.setVisible(true);
            } catch (Exception exception) {

            }
        }


        }
        System.out.println("entroooo");
        return codigo;
    }*/
    public void limpiarTrans(){
        this.detallestransferencia.clear();
        this.jtfFecha.setText("");
        this.jcbAlmacen.setSelectedIndex(-1);
        this.jcbUbicacion.setSelectedIndex(-1);
        this.jtfOrden.setText("");
        this.actualizarDetallesTransferencia();
        this.jcbZona.setEnabled(true);
        this.jbtAceptar.setEnabled(false);
    }

 public void obtenerCodigos() throws Exception{
         List<TransferenciaTO>  codigos= new ArrayList<TransferenciaTO> ();
          List<TransferenciaTO>  codigosTotal= new ArrayList<TransferenciaTO> ();
         if(this.jcbTipoIngreso.getSelectedIndex()>=0){
             if(this.jcbEmpresa.getSelectedIndex()>=0){
                 if(this.jcbZona.getSelectedIndex()>=0){
                    Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
                  
                    if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                        codigos= GestionPedidosDelegate.getInstance().obtenerCodigos(4);
                    }
                     for(TransferenciaTO dato: codigos){
                     boolean estado=false;
                     String  emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
                     if(emp.compareTo(dato.getEmpresa())==0){

                          estado=true;
                     }
                     if(estado){
                          for(int i=0; i<zonas.size(); i++){
                             if(zonas.get(i).getId_zona().compareTo(dato.getZona())==0){
                                codigosTotal.add(dato);
                              }
                          }
                     }
                    }
            this.intelliHintsCodigos.setCompletionList(codigosTotal);
            }
       }
       else{
       Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado una empresa");
      }
     }
      else{
      Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado un tipo de Salida");
    }
   }
    //PARA PEDIDOS
  
   private void cargaHintsIndependientes() {
  
        this.intelliHintsCodigos = new ListDataIntelliHints(this.jtfOrden, this.listacodigo);
  }
 
   public String RegistrarInventario() throws Exception{
        String codigo=null;
        boolean estado=true;
        List<DetalleMovimiento> detallesInv= new ArrayList<DetalleMovimiento>(1);
        Date fecha = new Date(VerificarDatos.verificaFecha(this.jtfFecha.getText()).getTime());
        Utiles_Fecha utf = new Utiles_Fecha(fecha);
        Parametros paramfec = Listas.getParametrosID("SU1");
        String ano = paramfec.getParam1();
        String mes = paramfec.getParam2();
        if ((!utf.getAnio().equalsIgnoreCase(ano)) || (!utf.getMes().equalsIgnoreCase(mes))) {
        Utiles_MensajesDialogo.mensajeError("La fecha debe coincidir con el mes actual: " + ano + " - " + mes);
        }
        else{
             Movimiento mov= new Movimiento();
            
        mov.setAnio(ano);
        mov.setFecha(fecha);
        mov.setMes(mes);
        mov.setTipoIngreso(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem()));
        Tipo tipoDocumento;
        if(this.jcbTipoDocumento.getSelectedItem()==null){
            tipoDocumento=null;
        }else{
            tipoDocumento =Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoDocumento.getSelectedItem());
        }
       
        if(tipoDocumento!=null)
        mov.setTipoDocumento(tipoDocumento);
        if(this.jtfSerie.getText().trim().length()>1)
        mov.setSerie(this.jtfSerie.getText());
        if(this.jtfNumero.getText().trim().length()>1)
        mov.setNumero(this.jtfNumero.getText());
        mov.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(1)));
        mov.setIdAlmacen(Utiles_Convertir.convertirTOAlmacen_AlmacenTO((AlmacenTO)this.jcbAlmacen.getSelectedItem()));
        mov.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
        mov.setIdSubalmacen(Utiles_Convertir.convertirTosubAlmacen_subAlmacenTO((SubAlmacenTO)this.jcbUbicacion.getSelectedItem()));
        mov.setEmpresa(Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()));
        mov.setObservacion(this.jtaObservacion.getText());
        boolean prod=false;
        if(this.jcbProduccion.isSelected()){
            prod=true;
        }
        mov.setIsProduccion(prod);
        int correlativo=1;
        String centro_costos=null;
        String unidad_organica=null;
        String cod_presupuestal=null;
        String cod_proyecto=null;
        String cod_inversion=null;
        for(int i=0; i< detallesbindingsalida.size(); i++){

             String suministro=this.detallesbindingsalida.get(i).getIdsuministro();
             Float cantidad= Float.parseFloat(this.jtDetalleSuministro.getValueAt(i, 2)+"");
             BigDecimal cantidadStock= GestionPedidosDelegate.getInstance().getSuministroEmpresa(suministro, ((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo()).getStock();             
             if(cantidadStock==null){
                 cantidadStock=BigDecimal.ZERO;
             }
             if(cantidadStock.compareTo(new BigDecimal(cantidad+""))<0){
                  Utiles_MensajesDialogo.mensajeFracaso("No has suficiente cantidades del suministro: "+detallesbindingsalida.get(i).getNomsuministro());
                  estado=false;
             }else if((this.detallesbindingsalida.get(i).getCantidad().compareTo(BigDecimal.ZERO)<1) ||
                     this.detallesbindingsalida.get(i).getPrecio().compareTo(BigDecimal.ZERO)<1 ){
                 Utiles_MensajesDialogo.mensajeFracaso("La cantidad o el precio no pueden ser valores cero para el suministro: "+detallesbindingsalida.get(i).getNomsuministro());
                  estado=false;
             }
             else{
                  
              DetalleMovimiento detall = new DetalleMovimiento();
              DetalleMovimientoPK detallepk= new DetalleMovimientoPK(correlativo, "");
              detall.setDetalleMovimientoPK(detallepk);
              detall.setCantidad(this.detallesbindingsalida.get(i).getCantidad());
              detall.setCcosto(centro_costos);
              detall.setCodInv(cod_inversion);
              detall.setCodPresupuestal(cod_presupuestal);
              detall.setFecha(fecha);
              detall.setIdLocalidad(new Localidad((this.listaLocalidad.get(0)).getId_localidad()));
              detall.setIdProyecto(cod_proyecto);
              detall.setIdSuministro(new Suministros(detallesbindingsalida.get(i).getIdsuministro()));
              detall.setId_unidad_organica(unidad_organica);
              detall.setPrecio(detallesbindingsalida.get(i).getPrecio());
              detall.setTipoMovimiento(Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.listaTipos.get(1)));
              detall.setValor(detall.getCantidad().multiply(detall.getPrecio()));
              detall.setIdZona(Utiles_Convertir.convertirToZona_ZonaTO((ZonaTO)this.jcbZona.getSelectedItem()));
              detall.setEstado_ubicacion(new Integer(0));
              correlativo++;
              detallesInv.add(detall);

             }
        }
       codigo=null;
        if(estado){
            try {
              codigo= GestionPedidosDelegate.getInstance().insertarSalida(Propiedades.getUsuario(),Propiedades.getMac(),mov,detallesInv);          
              Utiles_MensajesDialogo.mensajeExito();
              this.GenerarReporte(codigo);
            
            } catch (Exception exception) {
                 exception.printStackTrace();
            }
        }


        }
         return codigo;
      }
   void agregaDetalleSuministro(TblBeanBindingDetalleSalida detalle) throws Exception {
    try {

      if (verificaNoExisteSuministro(detalle)) {
        this.detallesbindingsalida.add(detalle);
        actualizaTablaDetalle();
        this.jbEliminaDetalle.setEnabled(true);
      } else {
        throw new Exception("El suministro " + detalle.getNomsuministro().trim() + "\nya fue ingresado");
      }
    } catch (Exception e) {
      throw e;
    }
  }
    private boolean verificaNoExisteSuministro(TblBeanBindingDetalleSalida detalle) {
    boolean retorno = true;
    for (TblBeanBindingDetalleSalida det : this.detallesbindingsalida) {
      if (det.getIdsuministro().equalsIgnoreCase(detalle.getIdsuministro())) {
        retorno = false;
        break;
      }
    }
    return retorno;
  }
    private void eliminarFila() {
        String id_sumi = this.jtDetalleSuministro.getValueAt(this.jtDetalleSuministro.getSelectedRow(), 0).toString().trim();

        for (TblBeanBindingDetalleSalida det : this.detallesbindingsalida) {
          if (det.getIdsuministro().equalsIgnoreCase(id_sumi)) {
            this.detallesbindingsalida.remove(det);
            break;
          }
        }
        actualizaTablaDetalle();
      }
      private void actualizaTablaDetalle() {
        this.bindingGroup = new BindingGroup();
        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.detallesbindingsalida, this.jtDetalleSuministro);
        this.bindingGroup.addBindingListener(new AbstractBindingListener() {

                      @Override public void synced(Binding binding) {
                        try{
                            if(!detallesbindingsalida.isEmpty()){

                                int selec=jtDetalleSuministro.getSelectedRow();
                                TblBeanBindingDetalleSalida detaord_aux= detallesbindingsalida.get(jtDetalleSuministro.convertRowIndexToModel(selec));
                                detaord_aux.setValor(detaord_aux.getCantidad().multiply(detaord_aux.getPrecio()));
                                actualizaTablaDetalle();

                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });
        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${idsuministro}"));

        columnBinding0.setColumnName("ID Suministro");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${nomsuministro}"));

        columnBinding1.setColumnName("Suministro");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

        columnBinding2.setColumnName("Cantidad");
        columnBinding2.setColumnClass(BigDecimal.class);
        columnBinding2.setEditable(false);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${precio}"));

        columnBinding3.setColumnName("Precio");
        columnBinding3.setColumnClass(BigDecimal.class);
        columnBinding3.setEditable(true);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${valor}"));

        columnBinding4.setColumnName("Valor");
        columnBinding4.setColumnClass(BigDecimal.class);
        columnBinding4.setEditable(false);


        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();
        int[] porcentajes= {15,40,15,15,15};
         try {
           Utiles_Tabla.definirAnchoColumnasJTable(jtDetalleSuministro, porcentajes);
          // MiTablePrint.autoSizeTableColumns(jtDetalleSuministro);
        } catch (Exception ex) {
            Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (this.detallesbindingsalida.size() > 0) {
          this.jbtAceptar.setEnabled(true);
          this.jbEliminaDetalle.setEnabled(true);
          this.jbtAceptar.requestFocus();
        } else {
          this.jbtAceptar.setEnabled(false);
          this.jbEliminaDetalle.setEnabled(false);
        }
      }
       private void limpiarInversion(){
       
        this.detallesbindingsalida.clear();
        this.pack();

    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingZona1 = new administracion.BeanBinding.CboBeanBindingZona();
        cboBeanBindingLocalidad1 = new administracion.BeanBinding.CboBeanBindingLocalidad();
        cboBeanBindingSubAlmacen1 = new administracion.BeanBinding.CboBeanBindingSubAlmacen();
        cboBeanBindingAlmacen1 = new administracion.BeanBinding.cboBeanBindingAlmacen();
        cboBeanBindingTipo1 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingTipo2 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        cboBeanBindingTipo3 = new administracion.BeanBinding.CboBeanBindingTipo();
        cboBeanBindingTipo4 = new administracion.BeanBinding.CboBeanBindingTipo();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfOrden = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDetalleSuministro = new javax.swing.JTable();
        this.jtDetalleSuministro.getTableHeader().setReorderingAllowed(false) ;
        jbtAgregar = new javax.swing.JButton();
        jbEliminaDetalle = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jtfFecha = new javax.swing.JFormattedTextField(this.mascaraFechaIngreso);
        jcbZona = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jcbAlmacen = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jcbUbicacion = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jcbTipoIngreso = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jbtAceptar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaObservacion = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jcbEmpresa = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jcbProduccion = new javax.swing.JCheckBox();
        jlblSerie = new javax.swing.JLabel();
        jtfSerie = new javax.swing.JTextField();
        jlblNumero = new javax.swing.JLabel();
        jtfNumero = new javax.swing.JTextField();
        jlblTipoDocumento = new javax.swing.JLabel();
        jcbTipoDocumento = new javax.swing.JComboBox();

        setIconifiable(true);
        setTitle("REGISTRAR SALIDAS DE ALMACEN");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("FECHA:");

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel7.setText("Nº DOCUMENTO");

        jtfOrden.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jtfOrden.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfOrdenActionPerformed(evt);
            }
        });
        jtfOrden.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfOrdenKeyPressed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DETALLE DE SALIDA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        jtDetalleSuministro.setFont(new java.awt.Font("Arial", 0, 12));
        jtDetalleSuministro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "DENOMINACION", "UNIDAD", "CANTIDAD PEDIDA", "CANTIDAD SALIDA"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtDetalleSuministro);

        jbtAgregar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/add.png"))); // NOI18N
        jbtAgregar.setMnemonic('A');
        jbtAgregar.setText("AGREGAR");
        jbtAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAgregarActionPerformed(evt);
            }
        });

        jbEliminaDetalle.setFont(new java.awt.Font("Arial", 0, 12));
        jbEliminaDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/remove.png"))); // NOI18N
        jbEliminaDetalle.setMnemonic('E');
        jbEliminaDetalle.setText("ELIMINAR");
        jbEliminaDetalle.setToolTipText("Eliminar el detalle seleccionado");
        jbEliminaDetalle.setEnabled(false);
        jbEliminaDetalle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbEliminaDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEliminaDetalleActionPerformed(evt);
            }
        });
        jbEliminaDetalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbEliminaDetalleKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 590, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbtAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEliminaDetalle)))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbEliminaDetalle)
                    .addComponent(jbtAgregar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE))
        );

        jLabel9.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel9.setText("SUCURSAL");

        jtfFecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfFechaKeyPressed(evt);
            }
        });

        jcbZona.setFont(new java.awt.Font("Arial", 0, 12));

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingZona1, eLProperty, jcbZona);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbZona.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbZonaItemStateChanged(evt);
            }
        });
        jcbZona.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbZonaKeyPressed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("ALMACEN:");

        jcbAlmacen.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingAlmacen1, eLProperty, jcbAlmacen);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbAlmacen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbAlmacenItemStateChanged(evt);
            }
        });
        jcbAlmacen.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbAlmacenKeyPressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel4.setText("UBICACION:");

        jcbUbicacion.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingSubAlmacen1, eLProperty, jcbUbicacion);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbUbicacion.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbUbicacionItemStateChanged(evt);
            }
        });
        jcbUbicacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbUbicacionKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("TIPO SALIDA:");

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo2, eLProperty, jcbTipoIngreso);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbTipoIngreso.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbTipoIngresoItemStateChanged(evt);
            }
        });
        jcbTipoIngreso.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbTipoIngresoKeyPressed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Arial", 1, 12));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/view_text.png"))); // NOI18N
        jButton3.setMnemonic('V');
        jButton3.setText("VER NOTA SALIDA");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 12));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jButton2.setMnemonic('C');
        jButton2.setText("CANCELAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.setEnabled(false);
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });
        jbtAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtAceptarKeyPressed(evt);
            }
        });

        jtaObservacion.setColumns(20);
        jtaObservacion.setRows(5);
        jScrollPane1.setViewportView(jtaObservacion);

        jLabel8.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel8.setText("OBSERVACION:");

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbEmpresaItemStateChanged(evt);
            }
        });
        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12));
        jCheckBox1.setText("OTRAS EMPRESAS");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jcbProduccion.setFont(new java.awt.Font("Arial", 1, 12));
        jcbProduccion.setText("PRODUCCION");

        jlblSerie.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jlblSerie.setText("SERIE");

        jlblNumero.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jlblNumero.setText("NUMERO");

        jlblTipoDocumento.setFont(new java.awt.Font("Arial", 1, 12));
        jlblTipoDocumento.setText("DOC. REFER:");

        jcbTipoDocumento.setFont(new java.awt.Font("Arial", 0, 12));

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingTipo3, eLProperty, jcbTipoDocumento);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbTipoDocumento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbTipoDocumentoKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel5)
                .addGap(64, 64, 64)
                .addComponent(jcbTipoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addGap(4, 4, 4)
                .addComponent(jtfOrden, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jCheckBox1)
                .addGap(6, 6, 6)
                .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlblTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(jcbTipoDocumento, 0, 193, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel9)
                .addGap(76, 76, 76)
                .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jlblSerie)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addComponent(jlblNumero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel6)
                .addGap(99, 99, 99)
                .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(68, 68, 68)
                .addComponent(jcbProduccion)
                .addContainerGap(199, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(79, 79, 79)
                        .addComponent(jbtAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(jButton3)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(80, 80, 80)
                .addComponent(jcbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addComponent(jLabel4)
                .addGap(27, 27, 27)
                .addComponent(jcbUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel5))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jcbTipoIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel7))
                            .addComponent(jtfOrden, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jlblTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jcbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel9))
                            .addComponent(jcbZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlblSerie)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jlblNumero))
                            .addComponent(jtfSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(jLabel6))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jcbProduccion)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbtAceptar)
                            .addComponent(jButton2)
                            .addComponent(jButton3)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jcbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel4))
                            .addComponent(jcbUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea registrar la nota de salida?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            if(this.jcbTipoIngreso.getSelectedIndex()>=0){
               Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
             if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                  if(this.jtfOrden.getText().compareTo("")==0){
                 Utiles_MensajesDialogo.mensajeFracaso("No se ha ingresado un transferencia");
                    }
                    else{
                        try {
                        codSalida=null;
                        //codSalida=this.registrarSalidaTransferencia();
                        if(codSalida!=null){
                             this.jbtAceptar.setEnabled(false);
                            limpiarTrans();
                            limpiarInversion();
                        }


                        } catch (Exception ex) {
                            Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                            Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de salida");
                        }
                    }
                 }
             else{
                try {
                    codSalida=null;
                    codSalida=this.RegistrarInventario();
                    if(codSalida!=null){
                        this.jbtAceptar.setEnabled(false);
                        this.limpiar();
                        limpiarInversion();
                    }

                    } catch (Exception ex) {
                        Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                        Utiles_MensajesDialogo.mensajeFracaso("No se pudo registrar la nota de salida");
                    }

               }
                try {

                } catch (Exception ex) {
                    Logger.getLogger(jifIngresosAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                }
                }
            else{
                 Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado un tipo de salida");
            }
          }
        
    }//GEN-LAST:event_jbtAceptarActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jcbZonaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbZonaItemStateChanged
       if(this.jcbTipoIngreso.getSelectedIndex()>=0){
         Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
         
          if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                try {
                     this.obtenerCodigos();
                } catch (Exception ex) {
                    Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
          else{
                try {
                  this.llenarComboAlmacenZona();
                  this.llenarComboLocalidad();
                  this.jcbAlmacen.setEnabled(true);
                  this.jcbUbicacion.setEnabled(true);

                  llenarComboLocalidad();
                } catch (Exception ex) {
                    Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
       }
         
    }//GEN-LAST:event_jcbZonaItemStateChanged

    private void jcbAlmacenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbAlmacenItemStateChanged
        if(this.jcbAlmacen.getSelectedIndex()>=0)
        this.llenarComboUbicacionAlmacen();
    }//GEN-LAST:event_jcbAlmacenItemStateChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    if(this.jcbTipoIngreso.getSelectedIndex()>=0){
         Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());
            if(codSalida!=null){
             
               if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                    this.GenerarReporteTrans(codSalida);
               }
               else{
                    this.GenerarReporte(codSalida);
               }

            }
            else{
            Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado una nota de salida");
            }
    }
               
    else{
        Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado un tipo de salida");
    }
       

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jcbAlmacenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbAlmacenKeyPressed
         if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcbUbicacion.requestFocus();
        }
    }//GEN-LAST:event_jcbAlmacenKeyPressed

    private void jcbTipoIngresoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbTipoIngresoKeyPressed
         if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfOrden.requestFocus();
        }
    }//GEN-LAST:event_jcbTipoIngresoKeyPressed

    private void jtfFechaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFechaKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.requestFocus();
        }
    }//GEN-LAST:event_jtfFechaKeyPressed

    private void jbtAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtAceptarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.doClick();
        }
    }//GEN-LAST:event_jbtAceptarKeyPressed

    private void jcbUbicacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbUbicacionKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfFecha.requestFocus();
        }
    }//GEN-LAST:event_jcbUbicacionKeyPressed

    private void jcbZonaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbZonaKeyPressed
         if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jcbTipoIngreso.requestFocus();
        }
    }//GEN-LAST:event_jcbZonaKeyPressed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            if(this.jcbEmpresa.getSelectedIndex()>=0){
                this.jcbZona.requestFocus();
            }
        }
    }//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jcbTipoIngresoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbTipoIngresoItemStateChanged
       if(this.jcbTipoIngreso.getSelectedIndex()>=0){
         Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());       
          if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                try {
                     this.limpiarTrans();
                     this.obtenerCodigos();
                     this.jbtAgregar.setVisible(false);
                     this.jbEliminaDetalle.setVisible(false);
                     this.jcbZona.setEnabled(true);
                     this.jcbAlmacen.setEnabled(false);
                     this.jcbUbicacion.setEnabled(false);
                     this.jtfOrden.setVisible(true);
                     this.jLabel7.setVisible(true);
                     this.jlblSerie.setVisible(false);
                     this.jlblNumero.setVisible(false);
                     this.jtfSerie.setVisible(false);
                     this.jtfSerie.setText("");
                     this.jtfNumero.setVisible(false);
                     this.jtfNumero.setText("");
                     this.jcbTipoDocumento.setVisible(false);
                     this.jlblTipoDocumento.setVisible(false);
                     this.pack();
                } catch (Exception ex) {
                    Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
          else{
                 this.jtfOrden.setVisible(false);
                 this.jLabel7.setVisible(false);
                 this.jbtAgregar.setVisible(true);
                 this.jbEliminaDetalle.setVisible(true);
                 
                 this.jcbZona.setEnabled(true);
                 this.jcbAlmacen.setEnabled(true);
                 this.jcbUbicacion.setEnabled(true);
                 this.jlblNumero.setVisible(true);
                 this.jlblSerie.setVisible(true);
                 this.jlblTipoDocumento.setVisible(true);
                 this.jtfSerie.setVisible(true);
                 this.jtfNumero.setVisible(true);
                 this.jcbTipoDocumento.setVisible(true);
                 this.pack();
            }
          if(t.getDescripcionValor().toString().compareTo("AJUSTE INVENTARIO")==0){
                 Utiles_MensajesDialogo.mensajeAlerta("No hay un inventario iniciado actualmente");
                 this.jcbTipoIngreso.setSelectedIndex(0);
            }
       }

    }//GEN-LAST:event_jcbTipoIngresoItemStateChanged

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        try {
            if (this.jCheckBox1.isSelected()) {
                this.jcbEmpresa.setEnabled(true);
            } else {
                this.jcbEmpresa.setEnabled(false);
            }
            this.llenarComboEmpresa();
            this.obtenerCodigos();
        } catch (Exception ex) {
            Logger.getLogger(jifSalidasAlmacen.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jcbEmpresaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbEmpresaItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbEmpresaItemStateChanged

    private void jcbUbicacionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbUbicacionItemStateChanged
      
    }//GEN-LAST:event_jcbUbicacionItemStateChanged

    private void jbtAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAgregarActionPerformed
        Frame frm = JOptionPane.getFrameForComponent((JInternalFrame)this);
        JDialog dialog = new JDialog(frm, true);
        dialog.setLocationRelativeTo(frm);
        dialog.setTitle("Insertar Detalles de Salidas");
        dialog.setDefaultCloseOperation(0);
        String empresa=Utiles_Convertir.convertirToEmpresa_EmpresaTO((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getIdEmpresa();
        jpAgregaDetalleSalida panel = new jpAgregaDetalleSalida(dialog, this,empresa);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
}//GEN-LAST:event_jbtAgregarActionPerformed

    private void jbEliminaDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEliminaDetalleActionPerformed

        try {
            if (this.jtDetalleSuministro.getSelectedRow() < 0) {
                Utiles_MensajesDialogo.mensajeError("Debe elegir un detalle");
                return;
            }
            if (Utiles_MensajesDialogo.mensajeConfirmacion("Esta seguro de eliminar el detalle?"))
                eliminarFila();
        } catch (Exception e) {
            e.printStackTrace();
        }
}//GEN-LAST:event_jbEliminaDetalleActionPerformed

    private void jbEliminaDetalleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbEliminaDetalleKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbEliminaDetalle.doClick();
        }
}//GEN-LAST:event_jbEliminaDetalleKeyPressed

    private void jtfOrdenKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfOrdenKeyPressed

        if(KeyEvent.VK_ENTER == evt.getKeyCode() ||KeyEvent.VK_TAB == evt.getKeyCode()  ){
            if(this.jcbTipoIngreso.getSelectedIndex()>-1){
                Tipo t=Utiles_Convertir.convertirToTipo_TipoTO((TipoTO)this.jcbTipoIngreso.getSelectedItem());

                if(t.getDescripcionValor().toString().compareTo("TRANSFERENCIA")==0){
                    this.jtfOrden.setText(this.intelliHintsCodigos.getSelectedHint().toString());
                    if(this.jtfOrden.getText().compareTo("")!=0){
                        this.obtenerTransferencia();
                        this.jcbAlmacen.setEnabled(false);
                        this.jcbUbicacion.setEnabled(false);
                    } else{
                        Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado una transferencia");
                    }

                } else{
                    this.jcbAlmacen.setEnabled(true);
                    this.jcbUbicacion.setEnabled(true);
                    this.jcbAlmacen.requestFocus();
                }
            } else{
                Utiles_MensajesDialogo.mensajeFracaso("No se ha seleccionado un tipo de salida");
            }

        }
}//GEN-LAST:event_jtfOrdenKeyPressed

    private void jtfOrdenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfOrdenActionPerformed
        this.jtfOrden.setText(this.intelliHintsCodigos.getSelectedHint().toString());
        this.limpiar();
        this.limpiarTrans();
        limpiarInversion();
}//GEN-LAST:event_jtfOrdenActionPerformed

    private void jcbTipoDocumentoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbTipoDocumentoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jtfSerie.requestFocus();
        }
}//GEN-LAST:event_jcbTipoDocumentoKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private administracion.BeanBinding.cboBeanBindingAlmacen cboBeanBindingAlmacen1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private administracion.BeanBinding.CboBeanBindingLocalidad cboBeanBindingLocalidad1;
    private administracion.BeanBinding.CboBeanBindingSubAlmacen cboBeanBindingSubAlmacen1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo1;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo2;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo3;
    private administracion.BeanBinding.CboBeanBindingTipo cboBeanBindingTipo4;
    private administracion.BeanBinding.CboBeanBindingZona cboBeanBindingZona1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbEliminaDetalle;
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JButton jbtAgregar;
    private javax.swing.JComboBox jcbAlmacen;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JCheckBox jcbProduccion;
    private javax.swing.JComboBox jcbTipoDocumento;
    private javax.swing.JComboBox jcbTipoIngreso;
    private javax.swing.JComboBox jcbUbicacion;
    private javax.swing.JComboBox jcbZona;
    private javax.swing.JLabel jlblNumero;
    private javax.swing.JLabel jlblSerie;
    private javax.swing.JLabel jlblTipoDocumento;
    private javax.swing.JTable jtDetalleSuministro;
    private javax.swing.JTextArea jtaObservacion;
    private javax.swing.JFormattedTextField jtfFecha;
    private javax.swing.JTextField jtfNumero;
    private javax.swing.JTextField jtfOrden;
    private javax.swing.JTextField jtfSerie;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
